package android.cst.hqu.edu.cn.basemvp.mvp.Base;

import java.lang.ref.Reference;
import java.lang.ref.WeakReference;

public abstract  class BasePresenter<V> {
    private Reference<V> mViewRef;
    public void attachView(V view){
        mViewRef= new WeakReference<>(view);
    }
    protected V getView(){
        return mViewRef.get();
    }
    public boolean isViewAttached(){
        return mViewRef!=null&&mViewRef.get()!=null;
    }
    public void detachView(){
        if(mViewRef!=null){
            mViewRef.clear();
            mViewRef=null;
        }
    }

}
